%% This is the main module for SVG Server
-module(httpResp).
-export([buildHeader/1]).

buildHeader(Data)->
	B1 = list_to_binary(Data),
	Len = size(B1),
  	[header(svg) ++ "Content-Length " ++ integer_to_list(Len) ++ "\r\n\r\n", B1].

header(text) -> 
    ["HTTP/1.0 200 Ok\r\n", powered_by(), content_type("text/html")];
header(svg) -> 
    ["HTTP/1.0 200 Ok\r\n", powered_by(), content_type("image/svg+xml")];
header(html) -> 
    ["HTTP/1.0 200 Ok\r\n", powered_by(), content_type("text/html")];
header(jpg)  -> 
    ["HTTP/1.0 200 Ok\r\n", powered_by(), content_type("image/jpeg")];
header(gif)  -> 
    ["HTTP/1.0 200 Ok\r\n", powered_by(), content_type("image/gif")];
header({redirect,To}) ->
    ["HTTP/1.0 302 Come and get it!\r\n",
     powered_by(), "Location: " ++ To ++ "\r\n"].

powered_by() ->
    "X-Powered-By: Erlang \r\n".

content_type(X) ->
    ["Content-Type: ", X, "\r\n"].